<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                template="./../../template/templateSGPF.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="corpo da página">
        <script>
            function decideMessage(value) {
                if (value) {
                    if (value.dialogConfimation === 'salvar') {
                        PF('save').show();
                    }
                    if (value.dialogConfimation === 'update') {
                        update.show();
                    }
                    if (value.dialogConfimation === 'error') {
                        error.show();
                    }
                }
            }
            function verify(value) {
                if (value.flag === "salvar") {
                    PF('confirmacao').show();
                }
                if (value.flag === "ok") {
                    PF('save').show();
                }
            }
            function disableConfirm() {
                $('[id=\'conteudo:confirm\']').attr('disabled', 'true');
            }
            function disableDecline() {
                $('[id=\'conteudo:decline\']').attr('disabled', 'true');
            }

            function removerEspacos(inputtext) {
                inputtext.value = inputtext.value.replace(/^\s+|\s+$/g, "");
            }
            
            function alteraMaiusculo(inputtext) {
                inputtext.value = inputtext.value.toUpperCase();
            }

        </script>
        <center><h1>#{cargoBean.titulo} </h1></center>
        <h:form id="formCargo" prependId="false">

            <div class="row-fluid">
                <div class="span6">
                    <div class="well-custom3">

                        <div class="row-fluid" >
                            <strong for="Nome" class="font-color-green">
                                Nome<strong style="color:red">*</strong>:</strong> 
                        </div>
                        <div class="row-fluid">
                            <div class="span6">
                                <p:inputText id="txt_nome" style="width: 97%; height: 30px;"
                                             value="#{cargoBean.cargo.nome}" 
                                             class="form-control"
                                             onkeyup="alteraMaiusculo(this)"/>                                
                            </div>
                            <div class="span6">
                                <p:messages for="msgNome" showDetail="true" autoUpdate="true" closable="true"/>                                           
                            </div>
                        </div>

                        <div class="row-fluid" style="margin-top: 1%">
                            <strong for="txtPopulacao" class="font-color-green">
                                Escolaridade: </strong> 
                        </div>
                        <div class="row-fluid">
                            <div class="span6">
                                <p:selectOneMenu id="sloEscolaridade"  
                                                 style="width: 97%; color: black;"
                                                 value="#{cargoBean.cargo.escolaridade}">
                                    <f:selectItem itemLabel="Selecione" itemValue=""
                                                  class="font-color-black"/>
                                    <f:selectItem itemLabel="Fundamental" itemValue="Fundamental"
                                                  class="font-color-black"/>
                                    <f:selectItem itemLabel="Médio" itemValue="Médio" 
                                                  class="font-color-black"/>
                                    <f:selectItem itemLabel="Superior" itemValue="Superior"
                                                  class="font-color-black"/>
                                </p:selectOneMenu>
                            </div>
                            <div class="span6">
                                <p:messages for="msgEscolaridade" showDetail="true" autoUpdate="true" closable="true"/>                                           
                            </div>
                        </div>

                    </div>

                </div>
                <div class="span6">
                    <div class="well-custom3">
                        <h:form id="frmLista">            
                            <p:dataTable id="tbCargo" 
                                         var="cargo" 
                                         value="#{cargoBean.cargos}"
                                         paginator="true" 
                                         rows="5" 
                                         emptyMessage="N&atilde;o h&aacute; dados para exibi&ccedil;&atilde;o"  
                                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} 
                                         {PageLinks} {NextPageLink} {LastPageLink}"
                                         resizableColumns="">

                                <p:column headerText="Cargo:"
                                          filterBy="#{cargo.nome}" style="width: 30%;"
                                          filterStyle="width:80%">
                                    <h:outputText value="#{cargo.nome}"/>
                                </p:column>

                                <p:column headerText="Escolaridade:"
                                          filterBy="#{cargo.escolaridade}" style="width: 12%;"                                          
                                          filterStyle="width:80%">
                                    <h:outputText value="#{cargo.escolaridade}"/>
                                </p:column>

                                <p:column style="width: 7%">
                                    <p:commandLink 
                                        title="Alterar"
                                        update=":formCargo"
                                        >
                                        <p:graphicImage value="/resources/img/edit.png"/>
                                        <!--<f:actionListener binding="{cargoBean.putInSession(cargo)}" />--> 
                                        <f:setPropertyActionListener
                                            value="#{cargo}"
                                            target="#{cargoBean.cargo}"/>
                                    </p:commandLink>
                                </p:column>
                            </p:dataTable>
                        </h:form>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="pull-left">                        
                        <p:commandButton style="width: 100px;"
                                         value="Salvar"                                    
                                         icon="ui-icon-disk"
                                         oncomplete="verify(args);"
                                         action="#{cargoBean.verificaCamposDialog()}"                                     
                                         update=":formConfirm"
                                         />
                        <p:commandButton style="width: 100px;" 
                                         icon="ui-icon-circle-close"
                                         value="Cancelar" 
                                         action="#{cargoBean.cancelar()}"
                                         ajax="false"
                                         update=":formCargo"/>
                    </div>
                </div>

            </div>

        </h:form>
        <p:confirmDialog global="true"
                         closable="false" 
                         message="O Cadastro foi salvo com sucesso!"  
                         header="Alerta" severity="alert" 
                         widgetVar="save"> 
            <h:form>
                <p:commandButton  id="buttonOK" 
                                  onclick="save.hide();" 
                                  value="OK" 
                                  ajax="false"
                                  action="#{cargoBean.irCadCargo()}"
                                  >
                </p:commandButton> 
            </h:form>
        </p:confirmDialog>
        <p:confirmDialog 
            global="true"
            header="Confirmação"
            message="Você confirma o envio destas informações?" 
            id="confirmDialog"                               
            severity="alert" 
            widgetVar="confirmacao" 
            closable="false" 
            width="400"
            >
            <h:form id="formConfirm">
                <div class="row-fluid">
                    <div class="well-custom4"> 
                        <div class="pull-left">
                            <div class="row-fluid">
                                <strong for="Nome" class="font-color-green">
                                    Nome<strong style="color:red">*</strong>: </strong> 
                                <h:outputText value="#{cargoBean.cargo.nome} "/>
                            </div>
                            <div class="row-fluid">                                    
                                <strong for="Escolaridade" class="font-color-green">
                                    Escolaridade:<strong style="color:red">*</strong>: </strong> 
                                <h:outputText value="#{cargoBean.cargo.escolaridade}" />                                 
                            </div>
                        </div>                                                                                
                    </div>                        
                    <div class="pull-left">   
                        <p:commandButton id="confirm" 
                                         onclick="PF('conf
                                                     irmacao').hide();"  
                                         value="Sim" 
                                         oncomplete="verify(args);"
                                         actionListener="#{cargoBean.salvar()}"
                                         update=":formCargo"
                                         />                          
                        <p:commandButton id="decline" value="Não" 
                                         onclick="PF('conf
                                                                 irmacao').hide();" 
                                         >                                         
                        </p:commandButton>
                    </div>
                </div>
            </h:form>
        </p:confirmDialog>

    </ui:define>

</ui:composition>
